package com.linwen.excise.leetcode;

public class _643子数组最大平均数 {
    public static void main(String[] args) {
        int[] nums = new int[]{0,4,0,3,2};
        int k = 1;
        System.out.println(findMaxAverage(nums, k));
    }
    public static double findMaxAverage(int[] nums, int k) {
        int sum = 0;
        int max = 0;
        for (int i = 0; i < nums.length; i++) {
            if(i<k){
                sum += nums[i];
                max = sum;
                continue;
            }
            sum = sum-nums[i-k]+nums[i];
            max = sum > max ? sum : max;
        }
        return max/(k*1.0);
    }
}
